<template>
	<!-- 区域添加 -->
	<div>
		<div class="edit-top">
			添加信息
			<i class="el-icon-close" @click='cancel'></i>
		</div>
		<div class="edit-content">
			<div class="edit-title">区域信息</div>
			<div class="edit-item">
				<label>区域编码</label><input v-model="info.code" type="text" />
			</div>
			<div class="edit-item">
				<label>区域名称</label><input v-model="info.name" type="text" />
			</div>
			<div class="edit-item">
				<label>所属区域</label><select v-model="info.parentId">
					<option value="0" selected="selected"></option>
					<option v-for="item in dep_list" :value="item.id">{{item.name}}</option>
				</select>
			</div>

		</div>
		<div class="edit-bottom">
			<span @click='cancel'>取消</span>
			<el-button @click='save' type="primary">保存</el-button>
		</div>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				dep_list: [],
				info: {
					name: '',
					code: '',
					parentId: 0,

				}
			}
		},
		mounted() {
			this.get_dep_list();
		},
		methods: {
			//获取单位列表
			get_dep_list() {
				var self = this;
				this.$axios.post(this.$global.serverIp + 'admin/sysProvince/findPage', {
						"limit": "10000",
						"page": "1"
					})
					.then(function(res) {
						if (res != '') {
							self.dep_list = res.data.list;
						}

					})
			},
			//点击添加按钮
			save() {
				if (this.info.name == "") {
					this.$popup.open('部门名称不能为空');
					return;
				}
				if (this.info.code == "") {
					this.$popup.open('部门编码不能为空');
					return;
				}
				var self = this;
				this.$axios.post(this.$global.serverIp + 'admin/sysProvince/save', self.info)
					.then(function(res) {
						if (res != '') {
							self.success('添加成功');
						}
					})
			},
			//添加成功
			success(content) {
				var self = this;
				this.$alert(content, '提示', {
					confirmButtonText: '确定',
					callback: action => {
						self.$emit("saveAdd", 2);
					}
				});
			},
			
			//点击取消
			cancel() {
				this.$emit("saveAdd", 1);
			}
		}
	}
	import '@/assets/css/edit.css'
</script>
